Use case: Get temperature with software/hardware trigger (polling) ¶
Note
In HAL1, there is no status flag indicating “end of measurement” in polling mode. To detect completion, the user must explicitly enable the “End of measurement” interrupt flag via
__HAL_DTS_ENABLE_IT(...)
and then poll that flag.
In HAL2, this interrupt is enabled automatically by
HAL_DTS_StartSensor(), and the driver uses its flag as a status indicator in
HAL_DTS_PollForSensorTemperature().
Warning:
When using polling mode, do not enable the NVIC interrupt request
DTS_IRQn; only the peripheral interrupt flag is used for polling.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
DTS_HandleTypeDef hdts;
int32_t temp;
hdts.Init.TriggerInput = DTS_TRIGGER_HW_NONE /* DTS_TRIGGER_LPTIMER2 for HW trigger*/;
HAL_DTS_Init(&hdts);
__HAL_DTS_ENABLE_IT(&hdts, DTS_IT_TS1_ITE);
HAL_DTS_Start(&hdts);
__HAL_DTS_GET_FLAG(&hdts, DTS_FLAG_TS1_ITE);
HAL_DTS_GetTemperature(&hdts, &temp);
HAL_DTS_Stop(&hdts);
|
hal_dts_handle_t hDTS;
int32_t temp;
HAL_DTS_Init(&hDTS, HAL_DTS);
hal_dts_config_t cfg = { .reference_clock = HAL_DTS_REFERENCE_CLOCK_PCLK,
.quick_measurement = HAL_DTS_QUICK_MEASUREMENT_DISABLE,
.high_speed_clock_division = 0 };
hal_dts_sensor_config_t sensor_cfg = { .trigger = HAL_DTS_TRIGGER_SOFTWARE, /* HAL_DTS_TRIGGER_LPTIM2_CH1 for HW trigger */
.sampling_time = HAL_DTS_SAMPLING_TIME_1_CYCLE };
HAL_DTS_SetConfig(&hDTS, &cfg);
HAL_DTS_SetConfigSensor(&hDTS, HAL_DTS_SENSOR_1, &sensor_cfg);
HAL_DTS_StartSensor(&hDTS, HAL_DTS_SENSOR_1);
HAL_DTS_PollForSensorTemperature(&hDTS, HAL_DTS_SENSOR_1, 1000);
HAL_DTS_GetSensorTemperature(&hDTS, HAL_DTS_SENSOR_1, &temp);
HAL_DTS_StopSensor(&hDTS, HAL_DTS_SENSOR_1);
|
Key changes ¶
In HAL2,
HAL_DTS_StartSensor()enables the end-of-measurement interrupt flag used byHAL_DTS_PollForSensorTemperature().In polling mode, do not enable
DTS_IRQn; only the peripheral interrupt flag is polled.HAL2 uses per-sensor configuration and per-sensor start/stop APIs.

